package domain.entities;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * Protocolo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see domain.entities.Protocolo
 * @author MyEclipse Persistence Tools
 */

public class ProtocoloDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(ProtocoloDAO.class);
	// property constants
	public static final String DISEASE = "disease";
	public static final String EUSU = "eusu";
	public static final String TITLE = "title";

	protected void initDao() {
		// do nothing
	}

	public void save(Protocolo transientInstance) {
		log.debug("saving Protocolo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Protocolo persistentInstance) {
		log.debug("deleting Protocolo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Protocolo findById(java.lang.String id) {
		log.debug("getting Protocolo instance with id: " + id);
		try {
			Protocolo instance = (Protocolo) getHibernateTemplate().get(
					"domain.entities.Protocolo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Protocolo> findByExample(Protocolo instance) {
		log.debug("finding Protocolo instance by example");
		try {
			List<Protocolo> results = (List<Protocolo>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Protocolo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Protocolo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Protocolo> findByDisease(Object disease) {
		return findByProperty(DISEASE, disease);
	}

	public List<Protocolo> findByEusu(Object eusu) {
		return findByProperty(EUSU, eusu);
	}

	public List<Protocolo> findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

	public List findAll() {
		log.debug("finding all Protocolo instances");
		try {
			String queryString = "from Protocolo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Protocolo merge(Protocolo detachedInstance) {
		log.debug("merging Protocolo instance");
		try {
			Protocolo result = (Protocolo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Protocolo instance) {
		log.debug("attaching dirty Protocolo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Protocolo instance) {
		log.debug("attaching clean Protocolo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProtocoloDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ProtocoloDAO) ctx.getBean("ProtocoloDAO");
	}

}